package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IForwardOrderActivityModel;
import com.wgts.wgts.mvp.presenter.IForwardOrderActivityPresenter;
import com.wgts.wgts.mvp.view.IForwardOrderActivityView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.resp.UserMoneyRecordEntity;

import java.util.List;

public class ForwardOrderActivityPresenter implements IForwardOrderActivityPresenter {

    private IForwardOrderActivityModel model;

    private IForwardOrderActivityView view;

    private Integer pageIndex = 1;

    private Integer pageSize = 20;


    public ForwardOrderActivityPresenter(IForwardOrderActivityModel model, IForwardOrderActivityView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void initPutAwardOrder() {

        pageIndex = 1;

        model.putAwardOrder(pageIndex, pageSize, new HttpResultSubscriber<List<UserMoneyRecordEntity>>() {
            @Override
            public void onSuccess(List<UserMoneyRecordEntity> entity) {
                if(entity.size() < pageSize){
                    view.initRecodList(entity, true);
                }else{
                    view.initRecodList(entity, false);
                    pageIndex++;
                }
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void loadPutAwardOrder() {
        model.putAwardOrder(pageIndex, pageSize, new HttpResultSubscriber<List<UserMoneyRecordEntity>>() {
            @Override
            public void onSuccess(List<UserMoneyRecordEntity> entity) {
                if(entity.size() < pageSize){
                    view.loadRecodList(entity, true);
                }else{
                    view.loadRecodList(entity, false);
                    pageIndex++;
                }
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }
}
